//
//  BaseViewController.m
//  EggSteward
//
//  Created by 王道林 on 16/8/26.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"night" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"day" object:nil];

}
- (void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"fanhui"] style:UIBarButtonItemStyleDone target:self action:@selector(backAction)];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.automaticallyAdjustsScrollViewInsets = NO;
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setUp];
}
- (void)setUp
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(night:) name:@"night" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dayTime:) name:@"day" object:nil];
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    BOOL is = [userDefault boolForKey:@"night"];
    if (is) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"night" object:nil userInfo:nil];
    } else
    {
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"day" object:nil userInfo:nil];
    }
    
}

- (void)dayTime:(NSNotification *)sender
{
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)night:(NSNotification *)sender
{
    self.view.backgroundColor = [UIColor colorWithWhite:0.565 alpha:0.585];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
